package net.lgpage.util;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Checker {

	public static class StringUtils {
		public static boolean isEmpty(String str) {
			return str == null || "".equals(str);
		}
		
		public static boolean containsSpecial(String str){
			String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]"; 
            Pattern p = Pattern.compile(regEx); 
            Matcher m = p.matcher(str);                 
            if( m.find()){
            	return true;
            }
            return false;
		}
		 /**
	     * 判断是否是Emoji
	     *
	     * @param codePoint 比较的单个字符
	     * @return
	     */
	    public static boolean isEmojiCharacter(char codePoint) {        return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) ||
	                (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
	                ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000)
	                && (codePoint <= 0x10FFFF));
	    }
	}

	public static class ListChecker {

		public static <T> boolean checkIsNotInList(List<T> list, int index) {
			if (list == null) {
				return true;
			} else {
				if (index < 0 || index > list.size() - 1) {
					return true;
				}
			}
			return false;
		}

		public static boolean isEmpty(List list) {
			if (list == null || list.size() == 0) {
				return true;
			}
			return false;
		}
	}

	public static class StringChecker {

		public static boolean isAllNull(String[] str) {
			boolean bl = true;
			for (String s : str) {
				if (!isNull(s)) {
					bl = false;
				}
			}
			return bl;
		}

		public static boolean isNull(String str) {
			if (str == null || "".equals(str)) {
				return true;
			} else {
				return false;
			}
		}

		public static boolean isNull(Integer i) {
			return i == null;
		}

		public static boolean isEmail(String str) {
			return str
					.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
		}

		public static boolean isAccountName(String str) {
			return str.matches("^[a-zA-Z][a-zA-Z0-9_]{4,15}$");
		}

		public static boolean containsSpecial(String str) {
			String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";
			Pattern p = Pattern.compile(regEx);
			Matcher m = p.matcher(str);
			return m.find();
		}
		public static boolean isPhoneNum(String str) {
			return str.matches("\\d{3}-\\d{8}|\\d{4}-\\d{7}|\\d{7}|\\d{8}|\\d{10,12}");
		}

		public static boolean isIdcard(String str) {
			return str.matches("\\d{15}|\\d{18}");
		}

		public static boolean isTel(String str) {
			return str.matches("^([0-9]{11})?$");
		}

		public static boolean is1Tel(String str) {
			return str.matches("1\\d{10}");
		}
		
	}
}
